<form class="form-horizontal" id="book-create" enctype="multipart/form-data" method="post">
    <fieldset>
        <legend>Thêm sách</legend>
        <div class="control-group">
            <label class="control-label" for="Title">Tên sách</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="Title" id="Title">
                <p class="help-block">Tối đa 200 ký tự</p>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="Cover">Hình bìa sách</label>
            <div class="controls">                
                <input type="file" id="Cover" class="input-file" name="Cover">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="PublisherID">Nhà xuất bản</label>
            <div class="controls">
                <select name="PublisherID" id="PublisherID">             
                    <option value="0">Chọn nhà xuất bản</option>
                    <?php foreach($this->publishers as $publisher) { ?>
                    <option value="<?php echo $publisher['PublisherID']; ?>"><?php echo $publisher['Name']; ?></option>                    
                    <?php } ?>
                </select>
            </div>
        </div>        
        <div class="control-group">
            <label class="control-label">Tác giả</label>                        
            <div class="controls">
                <select name="AuthorID[]" class="author_default">             
                    <option value="0">Chọn tác giả</option>
                    <?php foreach($this->authors as $author) { ?>
                    <option value="<?php echo $author['AuthorID']; ?>"><?php echo $author['Name']; ?></option>                    
                    <?php } ?>
                </select>                
                <a class="btn" href="javascript:;" id="add-author">Thêm tác giả</a>                                               
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Chuyên mục</label>                        
            <div class="controls">
                <select name="CategoryID[]" class="category_default">             
                    <option value="0">Chọn chuyên mục</option>
                    <?php foreach($this->categories as $category) { ?>
                    <option value="<?php echo $category['CategoryID']; ?>"><?php echo $category['Name']; ?></option>                    
                    <?php } ?>
                </select>                
                <a class="btn" href="javascript:;" id="add-category">Thêm chuyên mục</a>                                               
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="Quantity">Số lượng</label>                        
            <div class="controls">
                <input type="text" class="input-medium" name="Quantity" id="Quantity" value="1">                                                               
            </div>
        </div>
        <div class="form-actions">
            <button type="submit" class="btn btn-primary">Thêm sách</button>
            <a class="btn" href="javascript: window.location = '<?php echo $this->config->base_path; ?>/librarian/book'">Huỷ bỏ</a>
        </div>
    </fieldset>
</form>

<script type="text/javascript">
    $(function(){
        
        $('#book-create').on('submit', function(e) {
            e.preventDefault();
            $(this).ajaxSubmit({
                forceSync: true,
                dataType: 'json',
                beforeSubmit: function(){
                    
                },
                success: function(response, statusText, xhr, $form){
                	if (response.status == 0)
                    {
                        Utils.Message.Error(res.message);
                    }
					else
					{
					    window.location.href = config.base_path + "/librarian/book";
					} 
                }
            });
        });
        
        $('#add-author').on('click', function(){
            var $select = $('select.author_default').clone()
            .removeClass('author_default');
            
            $(this).parents('div.control-group').after($select);
            $select.wrap('<div class="control-group"><div class="controls"></div></div>');
        })
        
        $('#add-category').on('click', function(){
            var $select = $('select.category_default').clone()
            .removeClass('category_default');
            
            $(this).parents('div.control-group').after($select);
            $select.wrap('<div class="control-group"><div class="controls"></div></div>');
        })
    });
</script>